package chapter03.Demo03;

/**
 * 1.this 关键字
 * 类中this指类本身
 * this可以调用属性和方法
 * 2.static 关键字
 * 静态属性 一个地方修改类中静态属性 其他类的对象跟着变化
 */

class Student{
    String id; // 学生学号
    private String name;
    private int age;// 年龄
    private int gender;//性别 0男 1女

    public String dep = "信息工程系";
    public static String hoppy = "健身";

    // 构造方法
    public Student(){

    }
    public Student(String ID){
        id = ID;
    }
    public Student(String ID,String n){
        id = ID;
        name = n;
    }
    public void setName(String name){
        // name = name;// 错误写法 将形参 name 赋值给学生类name
        this.name = name;// this指该类本身
    }
    public String getName(){
        return name;
    }
    public void setAge(int age){
        if (age < 0 || age > 150) {
            System.out.println("输入年龄非法");
        }else {
            this.age = age;
        }
    }
    public void setGender(String g) {
        if (g.equals("男")) {
            gender= 0;
        }else {
            gender=1;
        }
    }
    public String getGender(){
        if (gender==0){
            return "男";
        }else {
            return "女";
        }
    }
}

public class Demo03 {
    public static void main(String[] args) {
        Student stu1 = new Student();
        stu1.setName("猪小明");
        stu1.setAge(18);
        System.out.println(stu1.dep);
        Student stu2 = new Student();
        System.out.println(stu2.dep);
        System.out.println("*************");
        stu1.dep = "宇宙系";
        System.out.println(stu1.dep);
        System.out.println(stu2.dep);
        System.out.println("查看爱好");
        System.out.println(stu1.hoppy);
        System.out.println(stu2.hoppy);
        System.out.println("*************");
        stu2.hoppy = "抽烟";
        System.out.println(stu1.hoppy);
        System.out.println(stu2.hoppy);
    }
}
